package com.rybbaby.tss.front.tssPayment.dao.imp;

import com.rybbaby.tss.core.web.dao.imp.GenericDao;
import com.rybbaby.tss.front.tssPayment.dao.IViewPaymentDetailsDao;
import com.rybbaby.tss.front.tssPayment.entity.ViewPaymentDetails;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @description 缴费表数据库操作实现
 * 
 * @author 雷春琼
 * 
 * @createDate 2017-08-10 上午12:22:55
 */
@Repository
public class ViewPaymentDetailsDaoImp extends GenericDao<ViewPaymentDetails> implements IViewPaymentDetailsDao {

    @Override
    public List<ViewPaymentDetails> packageDetailsList(String stuId) throws Exception {
        String sql = "select * from view_payment_details where stuId =? and paymentType in (1,3)  ORDER BY updateTime ASC";
        List<ViewPaymentDetails> listBySql = this.findListBySql(sql, ViewPaymentDetails.class, stuId);
        return listBySql;
    }

    @Override
    public List<ViewPaymentDetails> otherPaymentDetailsList(String stuId) throws Exception {
        String sql = "SELECT paymentType,SUM(amount)as amount,userName,MAX(updateTime) as updateTime FROM view_payment_details WHERE stuId = ? AND paymentType NOT IN (1, 2, 3)GROUP BY paymentType ORDER BY updateTime asc";
        List<ViewPaymentDetails> listBySql = this.findListBySql(sql, ViewPaymentDetails.class, stuId);
        return listBySql;
    }

    @Override
    public List<ViewPaymentDetails> DepositDetailsList(String stuId) throws Exception{
        String sql = "select * from view_payment_details where stuId =? and paymentType = 2 and depositStatus = 1 ORDER BY updateTime ASC";
        List<ViewPaymentDetails> listBySql = this.findListBySql(sql, ViewPaymentDetails.class, stuId);
        return listBySql;
    }

    @Override
    public List<ViewPaymentDetails> packagePaymentDetails(String packageId) throws Exception {
        String sql = "select * from view_payment_details where packageId = ?";
        List<ViewPaymentDetails> listBySql = this.findListBySql(sql, ViewPaymentDetails.class, packageId);
        return listBySql;
    }

    @Override
    public List<ViewPaymentDetails> packageRefundDetails(String packageId) throws Exception {
        String sql = "select * from view_payment_details where packageId = ? and paymentType in (1,3)";
        List<ViewPaymentDetails> listBySql = this.findListBySql(sql, ViewPaymentDetails.class, packageId);
        return listBySql;
    }

    @Override
    public List<ViewPaymentDetails> depositRefundDetails(String paymentId) throws Exception {
        String sql = "select * from view_payment_details where id = ?";
        List<ViewPaymentDetails> listBySql = this.findListBySql(sql, ViewPaymentDetails.class, paymentId);
        return listBySql;
    }

    @Override
    public Map<String,Object> OtherRefundDetails(String stuId, int paymentType) throws Exception{
        String sql = "SELECT\n" +
                "\tview_payment_details.*,\n" +
                "\tSUM(view_payment_details.amount) AS sumAmount\n" +
                "FROM\n" +
                "\tview_payment_details\n" +
                "WHERE\n" +
                "\tstuId = ?\n" +
                "AND paymentType = ?";
        return this.findOneForJdbc(sql,new Object[]{stuId,paymentType});
    }

    @Override
    public List<ViewPaymentDetails> getAllList() {
        return this.loadAll(ViewPaymentDetails.class);
    }

    @Override
    public List<ViewPaymentDetails> findListByIds(List<String> ids) {
        return this.loadByMultipleId(ViewPaymentDetails.class, ids);
    }
}
